package com.wizz.trade.information.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wizz.trade.information.dto.page.ItemPageDto;
import com.wizz.trade.information.entity.Item;
import com.wizz.trade.information.mapper.ItemMapper;
import com.wizz.trade.information.service.ItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wizz.trade.common.PageVo;
import com.wizz.trade.util.PageUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 收费项目表 服务实现类
 * </p>
 *
 * @author fyftless
 * @since 2023-04-02 04:26:06
 */
@Service
public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements ItemService {

    @Resource
    private ItemMapper itemMapper;

    @Override
    public void addItem(Item item) {
        itemMapper.insert(item);
    }

    @Override
    public void updateItem(Item item) {
        itemMapper.updateById(item);
    }

    @Override
    public void deleteItem(Integer id) {
        itemMapper.deleteById(id);
    }

    @Override
    public PageVo<Item> getPage(ItemPageDto itemPageDto) {
        LambdaQueryWrapper<Item> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(itemPageDto.getName()),Item::getName, itemPageDto.getName());
        queryWrapper.eq(!Objects.isNull(itemPageDto.getSvar()), Item::getSvar, itemPageDto.getSvar());
        IPage<Item> page = itemMapper.selectPage(PageUtil.initPage(itemPageDto), queryWrapper);
        return new PageVo<>(page);
    }

    @Override
    public List<Item> getAll() {
        return itemMapper.selectList(null);
    }

}
